<script setup>
    import { onMounted } from "vue"
    import { useRoute, useRouter } from "vue-router"
    import { useSelectMenu } from "../storePiana/index"
    const route = useRoute()
    const router = useRouter()
    const Tags = useSelectMenu()
    const tags = Tags.tabsList

    onMounted(() => {
        // console.log(tags)
    })
    function changeMenu(tag) {
        router.push(tag.path)
    }
    function handleClose(tag, index) {
        let length = tags.length - 1
        //处理pinia中的tabList
        Tags.closeTab(tag)
        //做第一个判断
        if (tag.name !== route.name) {
            return
        }

        //当深色的tag是最后一个
        if (index === length) {
            router.push({
                name: tags[index - 1].name,
            })
        } else {
            router.push({
                name: tags[index].name,
            })
        }
    }
</script>

<template>
    <div class="tags">
        <el-tag
            v-for="(tag, index) in tags"
            :key="tag.name"
            :closable="tag.name !== 'home'"
            :disable-transitions="false"
            :effect="route.name === tag.name ? 'dark' : 'plain'"
            @click="changeMenu(tag)"
            @close="handleClose(tag, index)"
            >{{ tag.label }}</el-tag
        >
    </div>
</template>

<style lang="less" scoped>
    .tags {
        width: 100%;
        padding: 20px;
        .el-tag {
            margin-right: 15px;
            cursor: pointer;
        }
    }
</style>
